package com.yjc.manager.entity;

import java.net.URL;
import java.util.List;
import java.util.Objects;

/**
 * 存储jar包信息
 *
 * @author 闫佳成
 * @version: 1.0
 * @since 2024/10/8 14:41
 */
public class JarInfo {
    private final String JAR_SUFFIX = ".jar";

    private String jarName;

    private URL[] urls;

    private List<String> classNames;

    public JarInfo(String jarName, URL[] urls, List<String> classNames) {
        this.jarName = jarName;
        this.urls = urls;
        this.classNames = classNames;
    }

    public String getJarName() {
        if (jarName.endsWith(JAR_SUFFIX)){
            return jarName.substring(0, jarName.length() - JAR_SUFFIX.length());
        }
        return jarName;
    }

    public void setJarName(String jarName) {
        this.jarName = jarName;
    }

    public URL[] getUrls() {
        return urls;
    }

    public void setUrls(URL[] urls) {
        this.urls = urls;
    }

    public List<String> getClassNames() {
        return classNames;
    }

    public void setClassNames(List<String> classNames) {
        this.classNames = classNames;
    }

    /**
     * jarname相等，就认定两个jar包是同一个
     * @param o
     * @return
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        JarInfo jarInfo = (JarInfo) o;
        return Objects.equals(jarName, jarInfo.jarName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(jarName);
    }
}
